﻿#include<iostream>

//在数组index处插入一个元素
//存在不足：原生数组无法删除最后一个元素
void DefaultInsert(int* array, int size, int num, int index) {	
	for (int i = size; i > index; i--) {
		array[i] = array[i - 1];
	}	
	array[index] = num;
}
//删除元素某个位置的元素
//存在不足：原生数组无法动态变更大小
void DefaultDelete(int* array, int size, int index) {
	for (int i = index; i < size - 1; i++)
		array[i] = array[i + 1];
}
int* DefaultExtend(int* array, int size, int enlarge) {
	//只能堆分配	
	int* res = new int[size + enlarge];
	for (int i = 0; i < size; i++) {
		res[i] = array[i];
	}
	delete[] array;	
	return res;
}

//cpp array
int main() {

	//stack
	int arr1[5];
	int arr2[4] = { 1,2,3 };

	//heap
	int* parr1 = new int[5];
	int* parr2 = new int[5] {1, 2, 3};


	//set
	int thirdValue = *(arr2 + 2);
	int thirdValue2 = *(&arr2[0] + 2);

	int* ptr = arr2;
	ptr += 2;
	int thirdValue3 = *ptr;
	int thirdValue4 = arr2[2];

	DefaultInsert(arr2, 3, 4, 1);
	//DefaultDelete(arr2, 3, 1);
	for (int i = 0; i < 4; i++) {
		std::cout << arr2[i] << std::endl;
	}

	//std::cout << thirdValue2 << std::endl;

	delete[] parr1;
	delete[] parr2;

	std::cin.get();
}